package com.scnu409.mimicontact;

import com.scnu409.utils.HttpUtils;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;
import android.widget.Toast;

public class StartActivity extends Activity implements AnimationListener{
	
	/*
	 * @param _sp  查询本地是否有用户存在
	 * @param welCome 欢迎界面的图
	 */
	private SharedPreferences _sp;
	ImageView welCome;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.activity_start);
        welCome=(ImageView)findViewById(R.id.welcome);
        _sp=getSharedPreferences("USER",MODE_PRIVATE);
        
       
        //打开应用时，产生动漫
        AlphaAnimation animation=new AlphaAnimation(0.3f,1);
        animation.setDuration(2000); //持续时间2秒
        animation.setFillAfter(true);
        welCome.setAnimation(animation);
        animation.setAnimationListener(this);
    }
    @Override
	public void onAnimationStart(Animation animation) {
	}

	@Override
	public void onAnimationEnd(Animation animation) {
		/*
		 *启动动漫结束后，查询本地是否有用户，没有，进入注册界面，有的话，进入home界面
		 */
		
		
		String userName=_sp.getString("userName", null);
		String userPsw=_sp.getString("userPsw", null);
		if(userName==null&&userPsw==null){
			Intent intent =new Intent (StartActivity.this,Home.class);
			startActivity(intent);
			finish();
		}
		else{
			Intent intent=new Intent(StartActivity.this,Login.class);
			startActivity(intent);
			finish();
		}
		
		/*
		int isNetWork=HttpUtils.getNetType(StartActivity.this);
		
		switch(isNetWork){
		case 1:
		case 2:{
			String userName=_sp.getString("useraName", null);
			String userPsw=_sp.getString("userPsw", null);
			if(userName!=null&&userPsw!=null){
				Intent intent =new Intent (StartActivity.this,Home.class);
				startActivity(intent);
				finish();
			}
			else{
				Toast.makeText(StartActivity.this, "没有连上WIFi", Toast.LENGTH_LONG);
			}
		};break;
		case 3:{
			//
			Intent intent =new Intent(StartActivity.this,Home.class);
			startActivity(intent);
			finish();
		};break;
		}
		*/
	}

	@Override
	public void onAnimationRepeat(Animation animation) {}
}
